function oscroll ( name, content )
{
	this.name = name;
	this._content = content;

	this._init ();
};

oscroll.prototype._init = function ()
{
	this._create_wrapper ();
	this._content.style.overflow = "scroll";

	if ( this._support_scrolling () )
	{
		this._init_scrolling ();
	} else {
		this._init_full ();
	}
};

oscroll.prototype._init_scrolling = function ()
{
	this._content.style.WebkitOverflowScrolling = "touch";
};

oscroll.prototype._init_full = function ()
{
	var t = document.createElement ( "div" );
	var self = this;

	t.className = "oscroll-track";
	this._wrapper.appendChild ( t );

	this._track = t;

	this._calc_height ();

	function f ( e )
	    {
		var st = self._content.scrollTop;
		var sh = self._content.scrollHeight;
		var h = self._content.clientHeight;
		var delta = st / ( sh - h );
		var t = self._track;

		var dx = Math.floor ( ( self._wrapper.clientHeight - ( self._track_h + ( self._track_margin * 2 ) ) ) * delta );
		t.style.WebkitTransform = "translate(0," + dx + "px)";
	    };
	setInterval ( f, 10 );
};

oscroll.prototype._calc_height = function ()
{
	var sh = this._content.scrollHeight;
	var ch = this._content.clientHeight;
	var mt = parseInt ( this._get_style ( this._track, "marginTop" ) );

	this._track_h = Math.floor ( ( ch / sh ) * ch );
	this._track_margin = mt;

	this._track.style.height = this._track_h + "px";
};

oscroll.prototype._create_wrapper = function ()
{
	var t = document.createElement ( "div" );
	var p = this._content.parentNode;

	t.className = "oscroll-wrapper";
	
	t.style.width  = this._content.clientWidth + "px"
	t.style.height = this._content.clientHeight + "px";

	p.insertBefore ( t, this._content );
	p.removeChild ( this._content );
	t.appendChild ( this._content );
	
	this._wrapper = t;
};

oscroll.prototype._support_scrolling = function ()
{
	var supported = false;
	(function() {
		var div = document.createElement('div');

		div.innerHTML = '<div style="-webkit-overflow-scrolling: touch;"></div>';
		supported = ( div.firstChild.style.WebkitOverflowScrolling !== undefined );

		delete div;
	})();

	return supported;
};

oscroll.prototype._get_style = function ( elem, style )
{
	var computed_style = null;

	if ( typeof ( elem.currentStyle ) != 'undefined' )
		computed_style = elem.currentStyle;
	else 
		computed_style = document.defaultView.getComputedStyle ( elem, null );

	if ( ! style )
		return computed_style;
	else
		return computed_style [ style ];
};
